<? $js = 'onClick="check_all(this)"'; ?>
<fieldset style="width:80%">
	<? if(empty($subject_id)) : //jika yang diklik adalah nama guru dengan tujuan menambah bidang studi ?>
		<legend>Data Bidang Studi</legend>
		<table class="list" width="75%" align=center>
			<tr>
				<th>No</th>
				<th><?php echo "Nama"?></th>
				<th><?php echo form_checkbox('check_list_all','all','',$js)?></th>
			</tr>
			<? $subjects = $this->subjects->lists(); 
				$num = 1;			
				foreach($subjects as $s) {
					$trclass = ($num % 2 == 0) ? 'zebra' : '';
			?>
			<tr class="<?php echo $trclass ?>">
				<td class="rownum"><?php echo $num ?></td>
				<td><?php echo $s['name'] ?></td>
				<td> <? 
					$teachings = $this->teachings->lists($school_year_id, $teacher['id'],$s['id']);
					if(count($teachings)>0) {
						foreach($teachings as $t)
							if($t['subject_id']==$s['id']){ 
								//cek apakah memiliki informasi kelas didalamnya. jika ya, maka disable checkboxnya
								
								$class_amount = $this->teachings->count($school_year_id, $teacher['id'],$s['id']);
								if($class_amount>0){
									echo '<input type="checkbox" DISABLED checked="checked" value="'. $s['id'].'" name="check_list['.$s['id'].']">';
								}
								else
									echo form_checkbox('check_list['.$s['id'].']',$s['id'],TRUE);
							}
					}
					else
						echo form_checkbox('check_list['.$s['id'].']',$s['id']);
					?>
				</td>
			</tr>
			<? 	$num++;
				} 
			?>
		</table>
		<ul class="prerequisites"> 
			<li>Bidang studi yang telah memiliki informasi kelas tidak dapat diganti atau dihapus.</li>
		</ul>
	<? else : //jika yang diklik adalah nama matpel, dengan tujuan menambah data kelas?>
		<? $subject = $this->subjects->get($subject_id); ?>
		<legend>Bidang Studi <?echo $subject['name']?> - Data Kelas</legend>
		<table class="list" width="75%" align=center>
			<tr>
				<th>No</th>
				<th>Kelas</th>
				<th><?php echo form_checkbox('check_list_all','all','',$js)?></th>
			</tr>
			<?  
				//$classes = $this->classes->lists();
				$classes = $this->classes->simple_lists($school_year_id);
				$num = 1;			
				foreach($classes as $c) {
					$trclass = ($num % 2 == 0) ? 'zebra' : '';
			?>
			<tr class="<?php echo $trclass ?>">
				<td class="rownum"><?php echo $num ?></td>
				<td><?php echo $c['name'] ?></td>
				<td> <? 
					$teachings = $this->teachings->lists($school_year_id, $teacher['id'],$subject_id,$c['id']);
					if(count($teachings)>0) {
						foreach($teachings as $t)
							if($t['class_id']==$c['id'])
								//cek apakah memiliki informasi nilai didalamnya. jika ya, maka disable checkboxnya
								
								$value_amount = $this->teachings->had_values($t['id']);
								if($value_amount>0){
									echo '<input type="checkbox" DISABLED checked="checked" value="'. $c['id'].'" name="check_list['.$c['id'].']">';
								}
								else
									echo form_checkbox('check_list['.$c['id'].']',$c['id'],TRUE);
								//echo form_checkbox('check_list['.$c['id'].']',$c['id'],TRUE);
					}
					else
						echo form_checkbox('check_list['.$c['id'].']',$c['id']);
					?>
				</td>
			</tr>
			<? 	$num++;
				} 
			?>
		</table>
		<ul class="prerequisites"> 
			<li>Kelas yang telah memiliki informasi nilai ulangan tidak dapat diganti atau dihapus.</li>
		</ul>
	<? endif ?>
</fieldset>